/* SPDX-License-Identifier: LGPL-3.0-or-later */
/*
 * Copyright(c) 2023 John Sanpe <sanpeqf@gmail.com>
 */

#include <bfdev/popcount.h>
#include <export.h>

export const bfdev_u8
bfdev_popcount_table[256] = {
    [0x00] = 0, [0x01] = 1, [0x02] = 1, [0x03] = 2,
    [0x04] = 1, [0x05] = 2, [0x06] = 2, [0x07] = 3,
    [0x08] = 1, [0x09] = 2, [0x0a] = 2, [0x0b] = 3,
    [0x0c] = 2, [0x0d] = 3, [0x0e] = 3, [0x0f] = 4,
    [0x10] = 1, [0x11] = 2, [0x12] = 2, [0x13] = 3,
    [0x14] = 2, [0x15] = 3, [0x16] = 3, [0x17] = 4,
    [0x18] = 2, [0x19] = 3, [0x1a] = 3, [0x1b] = 4,
    [0x1c] = 3, [0x1d] = 4, [0x1e] = 4, [0x1f] = 5,
    [0x20] = 1, [0x21] = 2, [0x22] = 2, [0x23] = 3,
    [0x24] = 2, [0x25] = 3, [0x26] = 3, [0x27] = 4,
    [0x28] = 2, [0x29] = 3, [0x2a] = 3, [0x2b] = 4,
    [0x2c] = 3, [0x2d] = 4, [0x2e] = 4, [0x2f] = 5,
    [0x30] = 2, [0x31] = 3, [0x32] = 3, [0x33] = 4,
    [0x34] = 3, [0x35] = 4, [0x36] = 4, [0x37] = 5,
    [0x38] = 3, [0x39] = 4, [0x3a] = 4, [0x3b] = 5,
    [0x3c] = 4, [0x3d] = 5, [0x3e] = 5, [0x3f] = 6,
    [0x40] = 1, [0x41] = 2, [0x42] = 2, [0x43] = 3,
    [0x44] = 2, [0x45] = 3, [0x46] = 3, [0x47] = 4,
    [0x48] = 2, [0x49] = 3, [0x4a] = 3, [0x4b] = 4,
    [0x4c] = 3, [0x4d] = 4, [0x4e] = 4, [0x4f] = 5,
    [0x50] = 2, [0x51] = 3, [0x52] = 3, [0x53] = 4,
    [0x54] = 3, [0x55] = 4, [0x56] = 4, [0x57] = 5,
    [0x58] = 3, [0x59] = 4, [0x5a] = 4, [0x5b] = 5,
    [0x5c] = 4, [0x5d] = 5, [0x5e] = 5, [0x5f] = 6,
    [0x60] = 2, [0x61] = 3, [0x62] = 3, [0x63] = 4,
    [0x64] = 3, [0x65] = 4, [0x66] = 4, [0x67] = 5,
    [0x68] = 3, [0x69] = 4, [0x6a] = 4, [0x6b] = 5,
    [0x6c] = 4, [0x6d] = 5, [0x6e] = 5, [0x6f] = 6,
    [0x70] = 3, [0x71] = 4, [0x72] = 4, [0x73] = 5,
    [0x74] = 4, [0x75] = 5, [0x76] = 5, [0x77] = 6,
    [0x78] = 4, [0x79] = 5, [0x7a] = 5, [0x7b] = 6,
    [0x7c] = 5, [0x7d] = 6, [0x7e] = 6, [0x7f] = 7,
    [0x80] = 1, [0x81] = 2, [0x82] = 2, [0x83] = 3,
    [0x84] = 2, [0x85] = 3, [0x86] = 3, [0x87] = 4,
    [0x88] = 2, [0x89] = 3, [0x8a] = 3, [0x8b] = 4,
    [0x8c] = 3, [0x8d] = 4, [0x8e] = 4, [0x8f] = 5,
    [0x90] = 2, [0x91] = 3, [0x92] = 3, [0x93] = 4,
    [0x94] = 3, [0x95] = 4, [0x96] = 4, [0x97] = 5,
    [0x98] = 3, [0x99] = 4, [0x9a] = 4, [0x9b] = 5,
    [0x9c] = 4, [0x9d] = 5, [0x9e] = 5, [0x9f] = 6,
    [0xa0] = 2, [0xa1] = 3, [0xa2] = 3, [0xa3] = 4,
    [0xa4] = 3, [0xa5] = 4, [0xa6] = 4, [0xa7] = 5,
    [0xa8] = 3, [0xa9] = 4, [0xaa] = 4, [0xab] = 5,
    [0xac] = 4, [0xad] = 5, [0xae] = 5, [0xaf] = 6,
    [0xb0] = 3, [0xb1] = 4, [0xb2] = 4, [0xb3] = 5,
    [0xb4] = 4, [0xb5] = 5, [0xb6] = 5, [0xb7] = 6,
    [0xb8] = 4, [0xb9] = 5, [0xba] = 5, [0xbb] = 6,
    [0xbc] = 5, [0xbd] = 6, [0xbe] = 6, [0xbf] = 7,
    [0xc0] = 2, [0xc1] = 3, [0xc2] = 3, [0xc3] = 4,
    [0xc4] = 3, [0xc5] = 4, [0xc6] = 4, [0xc7] = 5,
    [0xc8] = 3, [0xc9] = 4, [0xca] = 4, [0xcb] = 5,
    [0xcc] = 4, [0xcd] = 5, [0xce] = 5, [0xcf] = 6,
    [0xd0] = 3, [0xd1] = 4, [0xd2] = 4, [0xd3] = 5,
    [0xd4] = 4, [0xd5] = 5, [0xd6] = 5, [0xd7] = 6,
    [0xd8] = 4, [0xd9] = 5, [0xda] = 5, [0xdb] = 6,
    [0xdc] = 5, [0xdd] = 6, [0xde] = 6, [0xdf] = 7,
    [0xe0] = 3, [0xe1] = 4, [0xe2] = 4, [0xe3] = 5,
    [0xe4] = 4, [0xe5] = 5, [0xe6] = 5, [0xe7] = 6,
    [0xe8] = 4, [0xe9] = 5, [0xea] = 5, [0xeb] = 6,
    [0xec] = 5, [0xed] = 6, [0xee] = 6, [0xef] = 7,
    [0xf0] = 4, [0xf1] = 5, [0xf2] = 5, [0xf3] = 6,
    [0xf4] = 5, [0xf5] = 6, [0xf6] = 6, [0xf7] = 7,
    [0xf8] = 5, [0xf9] = 6, [0xfa] = 6, [0xfb] = 7,
    [0xfc] = 6, [0xfd] = 7, [0xfe] = 7, [0xff] = 8,
};

export const bfdev_bool
bfdev_popparity_table[256] = {
    [0x00] = bfdev_false, [0x01] =  bfdev_true, [0x02] =  bfdev_true, [0x03] = bfdev_false,
    [0x04] =  bfdev_true, [0x05] = bfdev_false, [0x06] = bfdev_false, [0x07] =  bfdev_true,
    [0x08] =  bfdev_true, [0x09] = bfdev_false, [0x0a] = bfdev_false, [0x0b] =  bfdev_true,
    [0x0c] = bfdev_false, [0x0d] =  bfdev_true, [0x0e] =  bfdev_true, [0x0f] = bfdev_false,
    [0x10] =  bfdev_true, [0x11] = bfdev_false, [0x12] = bfdev_false, [0x13] =  bfdev_true,
    [0x14] = bfdev_false, [0x15] =  bfdev_true, [0x16] =  bfdev_true, [0x17] = bfdev_false,
    [0x18] = bfdev_false, [0x19] =  bfdev_true, [0x1a] =  bfdev_true, [0x1b] = bfdev_false,
    [0x1c] =  bfdev_true, [0x1d] = bfdev_false, [0x1e] = bfdev_false, [0x1f] =  bfdev_true,
    [0x20] =  bfdev_true, [0x21] = bfdev_false, [0x22] = bfdev_false, [0x23] =  bfdev_true,
    [0x24] = bfdev_false, [0x25] =  bfdev_true, [0x26] =  bfdev_true, [0x27] = bfdev_false,
    [0x28] = bfdev_false, [0x29] =  bfdev_true, [0x2a] =  bfdev_true, [0x2b] = bfdev_false,
    [0x2c] =  bfdev_true, [0x2d] = bfdev_false, [0x2e] = bfdev_false, [0x2f] =  bfdev_true,
    [0x30] = bfdev_false, [0x31] =  bfdev_true, [0x32] =  bfdev_true, [0x33] = bfdev_false,
    [0x34] =  bfdev_true, [0x35] = bfdev_false, [0x36] = bfdev_false, [0x37] =  bfdev_true,
    [0x38] =  bfdev_true, [0x39] = bfdev_false, [0x3a] = bfdev_false, [0x3b] =  bfdev_true,
    [0x3c] = bfdev_false, [0x3d] =  bfdev_true, [0x3e] =  bfdev_true, [0x3f] = bfdev_false,
    [0x40] =  bfdev_true, [0x41] = bfdev_false, [0x42] = bfdev_false, [0x43] =  bfdev_true,
    [0x44] = bfdev_false, [0x45] =  bfdev_true, [0x46] =  bfdev_true, [0x47] = bfdev_false,
    [0x48] = bfdev_false, [0x49] =  bfdev_true, [0x4a] =  bfdev_true, [0x4b] = bfdev_false,
    [0x4c] =  bfdev_true, [0x4d] = bfdev_false, [0x4e] = bfdev_false, [0x4f] =  bfdev_true,
    [0x50] = bfdev_false, [0x51] =  bfdev_true, [0x52] =  bfdev_true, [0x53] = bfdev_false,
    [0x54] =  bfdev_true, [0x55] = bfdev_false, [0x56] = bfdev_false, [0x57] =  bfdev_true,
    [0x58] =  bfdev_true, [0x59] = bfdev_false, [0x5a] = bfdev_false, [0x5b] =  bfdev_true,
    [0x5c] = bfdev_false, [0x5d] =  bfdev_true, [0x5e] =  bfdev_true, [0x5f] = bfdev_false,
    [0x60] = bfdev_false, [0x61] =  bfdev_true, [0x62] =  bfdev_true, [0x63] = bfdev_false,
    [0x64] =  bfdev_true, [0x65] = bfdev_false, [0x66] = bfdev_false, [0x67] =  bfdev_true,
    [0x68] =  bfdev_true, [0x69] = bfdev_false, [0x6a] = bfdev_false, [0x6b] =  bfdev_true,
    [0x6c] = bfdev_false, [0x6d] =  bfdev_true, [0x6e] =  bfdev_true, [0x6f] = bfdev_false,
    [0x70] =  bfdev_true, [0x71] = bfdev_false, [0x72] = bfdev_false, [0x73] =  bfdev_true,
    [0x74] = bfdev_false, [0x75] =  bfdev_true, [0x76] =  bfdev_true, [0x77] = bfdev_false,
    [0x78] = bfdev_false, [0x79] =  bfdev_true, [0x7a] =  bfdev_true, [0x7b] = bfdev_false,
    [0x7c] =  bfdev_true, [0x7d] = bfdev_false, [0x7e] = bfdev_false, [0x7f] =  bfdev_true,
    [0x80] =  bfdev_true, [0x81] = bfdev_false, [0x82] = bfdev_false, [0x83] =  bfdev_true,
    [0x84] = bfdev_false, [0x85] =  bfdev_true, [0x86] =  bfdev_true, [0x87] = bfdev_false,
    [0x88] = bfdev_false, [0x89] =  bfdev_true, [0x8a] =  bfdev_true, [0x8b] = bfdev_false,
    [0x8c] =  bfdev_true, [0x8d] = bfdev_false, [0x8e] = bfdev_false, [0x8f] =  bfdev_true,
    [0x90] = bfdev_false, [0x91] =  bfdev_true, [0x92] =  bfdev_true, [0x93] = bfdev_false,
    [0x94] =  bfdev_true, [0x95] = bfdev_false, [0x96] = bfdev_false, [0x97] =  bfdev_true,
    [0x98] =  bfdev_true, [0x99] = bfdev_false, [0x9a] = bfdev_false, [0x9b] =  bfdev_true,
    [0x9c] = bfdev_false, [0x9d] =  bfdev_true, [0x9e] =  bfdev_true, [0x9f] = bfdev_false,
    [0xa0] = bfdev_false, [0xa1] =  bfdev_true, [0xa2] =  bfdev_true, [0xa3] = bfdev_false,
    [0xa4] =  bfdev_true, [0xa5] = bfdev_false, [0xa6] = bfdev_false, [0xa7] =  bfdev_true,
    [0xa8] =  bfdev_true, [0xa9] = bfdev_false, [0xaa] = bfdev_false, [0xab] =  bfdev_true,
    [0xac] = bfdev_false, [0xad] =  bfdev_true, [0xae] =  bfdev_true, [0xaf] = bfdev_false,
    [0xb0] =  bfdev_true, [0xb1] = bfdev_false, [0xb2] = bfdev_false, [0xb3] =  bfdev_true,
    [0xb4] = bfdev_false, [0xb5] =  bfdev_true, [0xb6] =  bfdev_true, [0xb7] = bfdev_false,
    [0xb8] = bfdev_false, [0xb9] =  bfdev_true, [0xba] =  bfdev_true, [0xbb] = bfdev_false,
    [0xbc] =  bfdev_true, [0xbd] = bfdev_false, [0xbe] = bfdev_false, [0xbf] =  bfdev_true,
    [0xc0] = bfdev_false, [0xc1] =  bfdev_true, [0xc2] =  bfdev_true, [0xc3] = bfdev_false,
    [0xc4] =  bfdev_true, [0xc5] = bfdev_false, [0xc6] = bfdev_false, [0xc7] =  bfdev_true,
    [0xc8] =  bfdev_true, [0xc9] = bfdev_false, [0xca] = bfdev_false, [0xcb] =  bfdev_true,
    [0xcc] = bfdev_false, [0xcd] =  bfdev_true, [0xce] =  bfdev_true, [0xcf] = bfdev_false,
    [0xd0] =  bfdev_true, [0xd1] = bfdev_false, [0xd2] = bfdev_false, [0xd3] =  bfdev_true,
    [0xd4] = bfdev_false, [0xd5] =  bfdev_true, [0xd6] =  bfdev_true, [0xd7] = bfdev_false,
    [0xd8] = bfdev_false, [0xd9] =  bfdev_true, [0xda] =  bfdev_true, [0xdb] = bfdev_false,
    [0xdc] =  bfdev_true, [0xdd] = bfdev_false, [0xde] = bfdev_false, [0xdf] =  bfdev_true,
    [0xe0] =  bfdev_true, [0xe1] = bfdev_false, [0xe2] = bfdev_false, [0xe3] =  bfdev_true,
    [0xe4] = bfdev_false, [0xe5] =  bfdev_true, [0xe6] =  bfdev_true, [0xe7] = bfdev_false,
    [0xe8] = bfdev_false, [0xe9] =  bfdev_true, [0xea] =  bfdev_true, [0xeb] = bfdev_false,
    [0xec] =  bfdev_true, [0xed] = bfdev_false, [0xee] = bfdev_false, [0xef] =  bfdev_true,
    [0xf0] = bfdev_false, [0xf1] =  bfdev_true, [0xf2] =  bfdev_true, [0xf3] = bfdev_false,
    [0xf4] =  bfdev_true, [0xf5] = bfdev_false, [0xf6] = bfdev_false, [0xf7] =  bfdev_true,
    [0xf8] =  bfdev_true, [0xf9] = bfdev_false, [0xfa] = bfdev_false, [0xfb] =  bfdev_true,
    [0xfc] = bfdev_false, [0xfd] =  bfdev_true, [0xfe] =  bfdev_true, [0xff] = bfdev_false,
};
